<?php

class SmartyOwner implements HttpForward {

    public static $owner_smarty = null;
    private $smarty;

    private function __construct() {
        
    }

    public static function getInstance($new_instance_smarty = null) {
        if (SmartyOwner::$owner_smarty == null) {
            SmartyOwner::$owner_smarty = new SmartyOwner();
        }
        if ($new_instance_smarty != null) {
            SmartyOwner::$owner_smarty->smarty = $new_instance_smarty;
        }


        return SmartyOwner::$owner_smarty;
    }

    public static function configLoad($dir, $section, $new_instance_smarty = null) {
        $smarty_ow = SmartyOwner::getInstance($new_instance_smarty);
        return $smarty_ow->getObject()->config_load($dir, $section);
    }

    public function assign($attr, $value) {
        $this->smarty->assign($attr, $value);
    }

    public function forward($page) {
        $this->smarty->display($this->smarty->template_dir . $page);
    }

    public function getObject() {
        return $this->smarty;
    }

    public function setTemplate($template_dir){
        $this->smarty->template_dir = $template_dir;
    }

    public function configDir($template_dir,$compile_dir,$config_dir){
        $this->smarty->template_dir = $template_dir;
        $this->smarty->compile_dir = $compile_dir;
        $this->smarty->config_dir = $config_dir;
    }

    public function getConfigVars($index,$attr){
        return SmartyOwner::getInstance()->getObject()->_config[$index]['vars'][$attr];
    }
}
